<?php

namespace app\api\validate;

use think\Validate;

class AccountScene extends Validate

{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'user_id' => ['require','number'],
        'username' => ['require','length'=>'2,10'],
        'password' => ['require','length'=>'6,12','regex' => '/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+$/'],
        'telephone' => ['require','regex'=>'/^1[3-9]{1}[0-9]{9}$/'],
        'real_name'=>['require','length'=>'2,10'],
        'user_type' => ['require','number'],
        "position" => ['require','number'],
        "server_rate" => ['number','between:0,100'],
        "group_id" => ['number'],
        "is_main" => ['number'],
        "data_state" => ['number','require'],


    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => '用戶名不能为空',
        'username.length' => '用戶名长度为2-10个字符',
        'username.unique' => '用戶名已被注册',
        'password.require' => '密码不能为空',
        'password.length' => '密码必须6-12个字符',
        're_password.require' => '确认密码不能为空',
        're_password.length' => '确认密码必须6-12个字符',
        'password.regex' => '密码必须为数字字母组合',
        're_password.regex' => '密码必须为数字字母组合',
        'telephone.require' => '手机号码不能为空',
        'telephone.regex' => '请输入正确的手机号',
        'user_type.require' => '账户类型不能为空',
        'position.require' => '请选择职位',
        'server_rate.number' => '费率必须为数值',
        'server_rate.between' =>'费率值只能在0-100之间',
        'group_id.number' =>'必须为数值',
        'is_main.number' =>'必须为数值',
        'data_state.number' =>'必须为数值',
        'data_state.require' =>'未设置状态',
    ];
    /**
     *
     * @return User
     */
    public function sceneRegister()
    {
        return $this->only(['username','password'])
            ->append('username','unique:account,username');
    }

    protected $scene = [
        'login'  =>  ['username','password'],
        'update_state'  =>  ['user_id','data_state'],
        'register'  =>  ['password','real_name','username','telephone','user_type','position','server_rate','group_id','is_main'],
        'change_password' => ['password',"re_password"],
        'adminchange_password' => ['password',"re_password",'user_id'],
        'update' => ['user_id','username','telephone','user_type','position','server_rate','group_id','is_main'],
        'change_user' => ['real_name','telephone']
    ];
}